<?php 
session_start();
if ($_SESSION['auth'] != true && $_SESSION['rule'] != "ADMIN") {
	die('Not log in');
}
include("includes/adminController.php");

$r = getReader($_GET['username']);
//$r = $readers[0];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Admin</title>
<link href="itelement.css" rel="stylesheet" type="text/css" />
<script src="script/jquery.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready (
	function () {
		var rank = '<? echo $r['rank'];?>';
		//alert(rank);
		$('#rank').val(rank);
		$('#editReader').click(
			function(){
				var err = readerReq();
				if(err != ''){
					$('#status').show('fast');
					$('#status').html(err);
					return;
				}
				//edit channel
				var serialize = $('form').serializeArray( );
				$('#status').show('fast');
				$('#status').text('Wait server...');
				$.post("admin_operation.php?action=edit_reader", serialize,
				  function(data){
					$('#status').text(data);
					$('#status').hide(300);
				  });
			}
		);
	}
);
function readerReq(){
	var br = '<br />';
	var err = '';
	if($('#username').val()==''){
		err += 'o  Username field requires'+br;
	}
	if($('#fname').val()==''){
		err += 'o  Firstname field requires'+br;
	}
	if($('#lname').val()==''){
		err += 'o  Lastname field requires'+br;
	}
	if($('#company').val()==''){
		err += 'o  Company field requires'+br;
	}
	if(err != '')err = err.substring(0,err.length-br.length);
	return err;
}
</script>
</head>
<body>
<form>
	  	  <div class="viewer-head">
		  	<div class="viewer-head-left">Edit Reader</div>
			<!--<div class="viewer-head-right"><input type="button" value="reset"></div>-->
		  </div>
		  <div class="input">
			Username (can't change)
			  <div>
			  <input type="hidden" name="username" value="<? echo $r['username'];?>">			  
			  <input style="width:100%; color:#999999" type="text" value="<? echo $r['username'];?>">
			</div>
		  </div>
		  <div class="input">
			New Password (leave blank if don't edit password)
			  <div>
			  <input style="width:100%" id="password" name="password" type="password" value="">
			</div>
		  </div>
		  <div class="input">
			Firstname
			  *
			  <div>
			  <input style="width:100%" id="fname" name="fname" type="text" value="<? echo $r['fname']?>">
			</div>
		  </div>
		  <div class="input">
			Lastname
			  *
			  <div>
			  <input style="width:100%" id="lname" name="lname" type="text" value="<? echo $r['lname']?>">
			</div>
		  </div>
		  <div class="input">
			Company
			  *
			  <div>
			  <input style="width:100%" id="company" name="company" type="text" value="<? echo $r['company']?>">
			</div>
		  </div>
		  <div class="input">
			Secret Rank
			  *
			  <div>
			  <select name="rank" name="rank">
			  	<option value="1" <?if($r['rank']==1) echo "selected";?> >public</option>
			  	<option value="2" <?if($r['rank']==2) echo "selected";?> >member</option>
				<option value="3" <?if($r['rank']==3) echo "selected";?> >secret</option>
			  </select>
			</div>
		  </div>
		  <div id="status"></div>
		  <!--<input type="submit" value="&nbsp;&nbsp;edit&nbsp;&nbsp;" />-->
		  <input type="button" value="&nbsp;&nbsp;edit&nbsp;&nbsp;" id="editReader">
</form>
</body>
</html>